package com.wfuhui.modules.oms.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wfuhui.modules.oms.entity.UserCouponEntity;
import com.wfuhui.modules.oms.service.UserCouponService;
import com.wfuhui.modules.sys.controller.AbstractController;
import com.wfuhui.common.utils.PageUtils;
import com.wfuhui.common.utils.Query;
import com.wfuhui.common.utils.R;




/**
 * 用户优惠券
 *
 */
@RestController
@RequestMapping("/usercoupon")
public class UserCouponController extends AbstractController {
	@Autowired
	private UserCouponService userCouponService;
	
	@RequestMapping("/listAll")
	@RequiresPermissions("usercoupon:list")
	public R listAll(@RequestParam Map<String, Object> params){
		//查询列表数据
		List<UserCouponEntity> userCouponList = userCouponService.queryList(params);
		return R.ok().put("userCouponList", userCouponList);
	}
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("usercoupon:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<UserCouponEntity> userCouponList = userCouponService.queryList(query);
		int total = userCouponService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(userCouponList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("usercoupon:info")
	public R info(@PathVariable("id") Integer id){
		UserCouponEntity userCoupon = userCouponService.queryObject(id);
		
		return R.ok().put("userCoupon", userCoupon);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("usercoupon:save")
	public R save(@RequestBody UserCouponEntity userCoupon){
		userCouponService.save(userCoupon);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("usercoupon:update")
	public R update(@RequestBody UserCouponEntity userCoupon){
		userCouponService.update(userCoupon);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("usercoupon:delete")
	public R delete(@RequestBody Integer[] ids){
		userCouponService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
